# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=babl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}"-git)
pkgver=0.1.84
pkgrel=1
pkgdesc="Dynamic Pixel Format Translation Library (mingw-w64)"
arch=('any')
url="http://gegl.org/babl/"
license=("GPL-3.0+" "LGPL-3.0+")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-lcms2")
options=('strip' 'staticlibs')
source=(#"${_realname}"::"git+https://git.gnome.org/browse/babl"
        https://download.gimp.org/pub/babl/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-file-open-unicode.patch)
sha256sums=('e7e38b8441f77feb9dc8231cb434a86190a21f2f3692c281457e99d35e9c34ea'
            '98cf43394eb1d1a8140438fbb745ed31f3768c07086afab297e4be9d609d07c5')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-file-open-unicode.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix=${MINGW_PREFIX} \
    --buildtype=plain \
    -Dwith-lcms=true \
    -Denable-gir=true \
    "../${_realname}-${pkgver}"
  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ninja install
}
